package com.xhtranslate.common.vo;


import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

/**
 * @author liuxuhuang
 * @date 2022年06月18日 21:54
 * @desc 返回前端类
 */
public class ResponseVO<T> implements Serializable {
    /**
     * 返回代码 (value = "返回代码", name = "返回码")
     */
    private Integer code;
    /**
     * 返回提示 (value = "返回提示", name = "返回提示")
     */
    private String message;
    /**
     * 返回数据 (value = "返回数据", name = "返回数据")
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;


    /**
     * 操作成功
     *
     * @return
     */
    public static ResponseVO succ() {
        return new ResponseVO(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg());
    }

    /**
     * 操作成功
     *
     * @return
     */
    public static ResponseVO succ(ResponseEnum responseEnum) {
        return new ResponseVO(responseEnum.getCode(), responseEnum.getMsg());
    }

    /**
     * 操作成功
     *
     * @return
     */
    public static ResponseVO succ(Object data) {
        return new ResponseVO(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), data);
    }

    /**
     * 异常返回
     *
     * @return
     */
    public static ResponseVO exception() {
        return new ResponseVO(ResponseEnum.FAIL.getCode(), ResponseEnum.FAIL.getMsg());
    }

    /**
     * 自定义返回
     *
     * @param responseEnum
     * @return
     */
    public static ResponseVO exception(ResponseEnum responseEnum) {
        return new ResponseVO(responseEnum.getCode(), responseEnum.getMsg());
    }

    /**
     * 自定义返回
     */
    public static ResponseVO exception(Object o) {
        return new ResponseVO(ResponseEnum.FAIL.getCode(), ResponseEnum.FAIL.getMsg(), o);
    }

    public ResponseVO() {
    }

    public ResponseVO(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseVO(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
